# $Id$
# Maintainer: Dan McGee <dan@archlinux.org>

pkgbase=doxygen
pkgname=('doxygen' 'doxygen-docs')
pkgver=1.8.13
pkgrel=3
license=('GPL')
arch=(i686 x86_64)
url="http://www.doxygen.org/"
makedepends=('cmake' 'gcc-libs' 'flex' 'qt5-base' 'texlive-core' 'ghostscript'
             'texlive-latexextra' 'graphviz' 'python2')
source=(http://ftp.stack.nl/pub/users/dimitri/${pkgname}-${pkgver}.src.tar.gz doxygen-segfault.patch)
md5sums=('0fa414975f8cd6d30e126c28327c1f7c'
         '168442765e75a07602632a691b7e6d8e')
sha1sums=('a3c812346d2ebd7b2e79ed1fec3a6aa3aedd5f7b'
          '58d927f6b5c63ffa12692e862ec439c527680413')

prepare() {
  mkdir build

  cd "${srcdir}/${pkgname}-${pkgver}"
  # Install the man pages in the right place
  sed -i 's:DESTINATION man/man1:DESTINATION "${CMAKE_INSTALL_PREFIX}/share/man/man1":g' \
    doc/CMakeLists.txt

  patch -Np1 -i $srcdir/doxygen-segfault.patch
}

build() {
  cd build

  cmake "../${pkgbase}-${pkgver}" \
    -DCMAKE_INSTALL_PREFIX:PATH=/usr \
    -DDOC_INSTALL_DIR:PATH=share/doc/doxygen \
    -DPYTHON_EXECUTABLE:FILE=/usr/bin/python2 \
    -Dbuild_doc:BOOL=ON \
    -Dbuild_wizard:BOOL=ON

  make
  make docs
}

check(){
  cd build
  make tests
}

package_doxygen() {
  pkgdesc="A documentation system for C++, C, Java, IDL and PHP"
  depends=('gcc-libs')
  optdepends=('graphviz: for caller/callee graph generation'
              'qt5-base: for doxywizard')

  cd build
  make DESTDIR="$pkgdir" install

  # Docs are in 'doxygen-docs'
  rm -rf "${pkgdir}/usr/share/doc"
}

package_doxygen-docs() {
  pkgdesc="Developer documentation for doxygen"

  cd build
  make DESTDIR="${pkgdir}" install

  rm -rf "${pkgdir}/usr/bin"
  rm -rf "${pkgdir}/usr/share/man"
}
